package com.trg.flex
{
	/**
	 * <p>This class is useful for filtering lists of objects based on a single property.
	 * To use it, specify the property to filter on and the value to campare the property to.
	 * Then set one of the comparison methods (equal, lessThan, greaterThan, lessThanOrEqual,
	 * greaterThanOrEqual) as the filterFunction on the collection.
	 * 
	 * <p>The value can be changed, but the property is fixed when the constructor is called. After
	 * changing the value, you will probably need to call refresh() on the collection.
	 * 
	 * <p>NOTE: This does not allow nested properties. For nested properties use <code>NestedPropertyFilter</code>
	 * 
	 * @see NestedPropertyFilter
	 */
	public class PropertyFilter
	{
		// property to compare
		public var property:String;
		
		// the value to compare the property to (for example the id of the selected server)
		public var value:Object;
		
		public function PropertyFilter(prop:String, value:Object = null)
		{
			this.property = prop;
			this.value = value;
		}
		
		public function equal(o:Object):Boolean {
			return o[property] == value;
		}
		
		public function lessThan(o:Object):Boolean {
			return o[property] < value;
		}
		
		public function greaterThan(o:Object):Boolean {
			return o[property] > value;
		}
		
		public function lessThanOrEqual(o:Object):Boolean {
			return o[property] <= value;
		}
		
		public function greaterThanOrEqual(o:Object):Boolean {
			return o[property] >= value;
		}
	}
}